Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize gvars with their pointer values in create_native #50838

Merged
merged 1 commit into from
Aug 10, 2023

Conversation

pchintalapudi
Copy link
Member

GPUCompiler won't have access to the runtime pointers for global variables emitted from jl_create_native, so we need to provide them here.

@pchintalapudi pchintalapudi added compiler:codegen Generation of LLVM IR and native code compiler:llvm For issues that relate to LLVM labels Aug 8, 2023
@vtjnash
Copy link
Member

vtjnash commented Aug 9, 2023

I thought we had exported an accessor to get the mapping from index to global back, which avoids the need to embed runtime state like this. But the PR looks good to merge anyways if it is fixing issues for now.

@pchintalapudi
Copy link
Member Author

Given that we have external consumers of jl_create_native modules, I think it's better to have the module be as complete and runnable as possible, without needing a side table to finish it off.

@vchuravy vchuravy merged commit 2d24155 into master Aug 10, 2023
@vchuravy vchuravy deleted the pc/init-gvs branch August 10, 2023 14:20
@vchuravy
Copy link
Member

I thought we had exported an accessor to get the mapping from index to global back

I don't think that is exported.

@vtjnash
Copy link
Member

vtjnash commented Aug 10, 2023

Oh, really? How do you manage to do anything without the expected struct accessors for the state:

julia/src/aotcompile.cpp

Lines 86 to 116 in 2d24155

typedef struct {
orc::ThreadSafeModule M;
std::vector<GlobalValue*> jl_sysimg_fvars;
std::vector<GlobalValue*> jl_sysimg_gvars;
std::map<jl_code_instance_t*, std::tuple<uint32_t, uint32_t>> jl_fvar_map;
std::vector<void*> jl_value_to_llvm;
std::vector<jl_code_instance_t*> jl_external_to_llvm;
} jl_native_code_desc_t;
extern "C" JL_DLLEXPORT_CODEGEN
void jl_get_function_id_impl(void *native_code, jl_code_instance_t *codeinst,
int32_t *func_idx, int32_t *specfunc_idx)
{
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
if (data) {
// get the function index in the fvar lookup table
auto it = data->jl_fvar_map.find(codeinst);
if (it != data->jl_fvar_map.end()) {
std::tie(*func_idx, *specfunc_idx) = it->second;
}
}
}
extern "C" JL_DLLEXPORT_CODEGEN
void jl_get_llvm_gvs_impl(void *native_code, arraylist_t *gvs)
{
// map a memory location (jl_value_t or jl_binding_t) to a GlobalVariable
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
arraylist_grow(gvs, data->jl_value_to_llvm.size());
memcpy(gvs->items, data->jl_value_to_llvm.data(), gvs->len * sizeof(void*));
}

@vchuravy
Copy link
Member

We only use jl_get_function_id.

Can we use arraylist_t from Julia?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code compiler:llvm For issues that relate to LLVM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants